package com.rongshu.sendmessage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.rongshu.sendmessage.R;
import com.rongshu.sendmessage.bean.PaySelectBean;

import java.util.List;

/**
 * zhifu pay
 */
public class PayAdapter extends RecyclerView.Adapter<PayAdapter.ViewHolder> {

    private final Context context;
    private List<PaySelectBean> paySelectBeanList;
    private OnItemClickListener mOnItemClickListener;

    public PayAdapter(Context context,List<PaySelectBean> paySelectBeanList) {
        this.context = context;
        this.paySelectBeanList = paySelectBeanList;
    }

    public void setList(List<PaySelectBean> list) {
        this.paySelectBeanList = list;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(View itemView) {
            super(itemView);
        }
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup recyclerView, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.pay_select_item, recyclerView, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

        View itemView = holder.itemView;
        RelativeLayout re_item = itemView.findViewById(R.id.re_item);
        TextView tv_title = itemView.findViewById(R.id.tv_title);
        ImageView iv_select = itemView.findViewById(R.id.iv_select);
        PaySelectBean paySelectBean = paySelectBeanList.get(position);
        if (paySelectBean.isSelect()){
            re_item.setBackgroundResource(R.drawable.blue_line_white_content_shape);
            iv_select.setVisibility(View.VISIBLE);
            tv_title.setTextColor(context.getResources().getColor(R.color.main_color_new_1));
        }else{
            re_item.setBackgroundResource(R.drawable.gray_5_cover_shape);
            iv_select.setVisibility(View.GONE);
            tv_title.setTextColor(context.getResources().getColor(R.color.color_black_666666));
        }
        tv_title.setText(paySelectBean.getName());

        if (mOnItemClickListener != null) {
            itemView.setOnClickListener(v -> mOnItemClickListener.onClick(position));
        }

    }

    @Override
    public int getItemCount() {

        return paySelectBeanList.size();
    }

    public interface OnItemClickListener {
        void onClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }
}
